<template>
	<view>
		<view class="tab">
			<lrTabs :tabs="tabs" @change="change"></lrTabs>
		</view>


		<view v-if="orderList.length > 0">

			<view class="item" style="margin: 0 40upx 20upx;border-radius: 18upx;padding: 0 26upx 39upx;"
				v-for="(item, index) in orderList" :key="index" >

				<view class="text-line2">
					<text class="text-name2">状态</text>
					<text class="text-value2">{{filterNull(item.arrivalStatusStr)}}</text>
				</view>

				<u-line color="#EDEDED"></u-line>

				<view class="text-line2">
					<text class="text-name2">预约品牌/车系</text>
					<text class="text-value2">{{filterNull(item.brandName) + " " + filterNull(item.seriesName)}}</text>
				</view>

				<u-line color="#EDEDED"></u-line>

				<view class="text-line2">
					<text class="text-name2">预约车型</text>
					<text class="text-value2">{{filterNull(item.modelName)}}</text>
				</view>

				<u-line color="#EDEDED"></u-line>

				<view class="text-line2">
					<text class="text-name2">预约人</text>
					<text class="text-value2">{{filterNull(item.contact)}}</text>
				</view>

				<u-line color="#EDEDED"></u-line>

				<view class="text-line2">
					<text class="text-name2">联系电话</text>
					<text class="text-value2">{{filterNull(item.phone)}}</text>
				</view>

				<u-line color="#EDEDED"></u-line>

				<text
					style="font-size: 22upx;color: #666666;margin-top: 30upx;line-height: 36upx;">说明:  {{filterNull(item.reserveContent)}}</text>

				<view class="title-wrap" style="margin: 0;">

					<view class="title-warn">

					</view>

					<view class="btn-detail" style="margin: 10upx 0 0;" @click.stop="itemClick(item)">
						详情
					</view>
				</view>

			</view>

			<u-loadmore :status="loadingStatus" @loadmore="clickloadmore"></u-loadmore>
		</view>

		<no-data v-else></no-data>


	</view>
</template>

<script>
	import {cluessourcedriverlist, cluessourcedrivercount} from '../../../common/api.js'
	import lrTabs from '../../../components/activity/lr-tabs.vue'

	export default {
		components: {
			lrTabs
		},
		data() {
			return {
				tabs: [{
						code: 0,
						value: '预约成功'
					},
					{
						code: 0,
						value: '已到店'
					},
					{
						code: 0,
						value: '无效'
					}
				],
				pageNo: 1,
				arrivalStatus: 1,//	1.预约成功 2.已到店 3.无效
				loadingStatus: 'loading',
				orderList: []
			}
		},

		onLoad() {
			this.getData()
			this.getCount()
		},

		methods: {
			
			getCount(){
				cluessourcedrivercount().then(res=>{
					this.tabs[0].code = res.appointmentSucceededCount;
					this.tabs[1].code = res.arrivedStoreCount;
					this.tabs[2].code = res.invalidCount;
				})
			},
			
			getData() {
				cluessourcedriverlist ({
					params: {
						pageNo: this.pageNo,
						arrivalStatus:this.arrivalStatus
					}
				}).then(res => {
					if (this.pageNo == 1) {
						this.orderList = [];
						this.pageNo++;
						// uni.stopPullDownRefresh();

						this.loadingStatus = 'loadmore';
					} else {
						if (!uni.$u.test.isEmpty(res)) {
							this.pageNo++;

							this.loadingStatus = 'loadmore';
						} else {

							this.loadingStatus = 'nomore';
						}
					}

					if (!uni.$u.test.isEmpty(res)) {
						this.orderList = this.orderList.concat(res);
					}


				})
			},

			itemClick(item) {
				uni.navigateTo({
					url: './testdrive-orderdetail?cluesId='+item.cluesId
				})
			},

			clickloadmore() {
				this.getData();
				this.showloading = true;
				this.loadingStatus = 'loading';
			},
			
			change(index){
				console.log(index);
				this.arrivalStatus = index + 1;
				
				this.pageNo = 1;
				this.getData();
				
			}
		},

		onPullDownRefresh() {
			this.pageNo = 1;
			this.getData();
		},

		onReachBottom() {
			console.log('到底了');

			this.getData();
			this.showloading = true;
			this.loadingStatus = 'loading';
		}
	}
</script>

<style lang="scss" scoped>
	.tab {
		position: sticky;
		top: 0;
		background-color: #F5F5F5;
		z-index: 2;
	}

	.title-wrap {
		display: inline-flex;
		justify-content: space-between;
	}

	.title-warn {
		color: #E93131;
		background-color: #FFFFFF;
		white-space: nowrap;
		text-align: center;
		font-size: 26upx;
		line-height: 60upx;
		margin: 10upx 0upx;
		align-self: flex-end;
	}
</style>
